

import { Loading } from 'element-ui';

export const iframe = (e,content,elname,size,title)=>{
    e.$layer.iframe({
        content: {
            content: content, //传递的组件对象
            parent: e,//当前的vue对象
            data:elname
        },
        area:size,
        title:title
    });
}


export const addList = (t,url)=>{
    let elname = {}
    let size = [
        "800px","600px"
    ]
    const title = '新增' 
    iframe(t,url,elname,size,title)
}


export const ModifyList = (t,data,url)=>{
    const size = [
        "800px","700px"
    ]
    const title = '修改跳转管理'
    iframe(t,url,data,size,title)
}


export const RemoteList = (t,G_DATA,e,G_URL)=>{
    let url = G_URL
    let data = G_DATA
    t.$confirm('是否继续删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then((res) => {
        t.$axios.getAddressJson(url,data)
        .then(res=>{
            // console.log(res)
            t.CurrData()
        })
        .catch(res=>{
            // console.log(res)
        })
        t.$message({
            type: 'success',
            message: '删除成功!'
        });
    })
    .catch(() => {
        t.$message({
            type: 'info',
            message: '已取消删除'
        });          
    });
}




export const DataList = (t,G_DATA,G_URL)=>{
    // Loading.service({});
    let url = G_URL;
    let data = G_DATA
    t.$axios.getAddressJson(url,data)
    .then(res=>{
        // console.log(res)
        // console.log(res.data.data)
        t.total =  res.data.pages*2
        t.tableData = res.data.data
        if(res.data.data.length==0){
            this.$notify.error({
                title: '错误',
                message: '没有内容哦~'
            });
        }
        setTimeout(()=>{
            Loading.service({}).close();
        },100)
        
    })
    .catch(res=>{
        // console.log(res)
        // t.$notify.error({
        //     title: '错误',
        //     message: '发生未知错误'
        // });
    })
}


export const getChannel = (t)=>{//选择小程序
    let url = 'channel/getChannel'
    let data = {}
    t.$axios.getAddressJson(url,data)
    .then(res=>{
        
        t.options = res.data.data;
        // console.log(t.options)
    })
    .catch(res=>{
        // console.log(res)
        t.$notify.error({
            title: '错误',
            message: '发生未知错误'
        });
    })
}




export const AddData = (t,e,G_DATA,G_URL)=>{
    t.$refs[e].validate(valid => {
        if (valid) {
           t.$axios.getAddressJson(G_URL,G_DATA)
           .then(res=>{
            //   console.log(res)
               if(res.data.code==1){
                t.$notify({
                    title: '成功',
                    type: 'success'
                });
                t.$parent.CurrData()//刷新父元素接口
               }else{
                    t.$notify.error({
                        title: '发生未知错误！',
                    });
               }
               t.$layer.closeAll()//关闭弹层
           })
           .catch(res=>{
               t.$notify.error({
                title: '发生未知错误！',
            });
           })
        }
        else{
            t.$notify.error({
                title: '请完善信息！',
            });
            return false;
        }
        t.$layer.closeAll()//关闭弹层
    });
}



//富文本编辑器
export const toolbarOptions = ()=>{
    return [
        ['bold', 'italic', 'underline', 'strike'],, // 加粗、斜体
        [{ 'header': [1, 2, 3, 4, 5, 6, false] }],//字体大小
        [{ header: 1 }, { header: 2 }], //H1、H2
        [{ list: "ordered" }, { list: "bullet" }], //排序
        [{ direction: "rtl" }], // //左对齐、右对齐
        [{ color: [] }, { background: [] }], //字体颜色
        [{ align: [] }],//对齐方式
        ["image"],//链接，图片
    ]
}